import os
import cv2

path_yuv420sp = r'/media/fang/3441-913C/img/tsr'

Names = []
for root, dirs, files in os.walk(path_yuv420sp):
    for file in files:
        Names.append(root + '/' + file)

i = 0
while i < len(Names):
    img = cv2.imread(Names[i])
    cv2.imshow('img', img)
    key = cv2.waitKey(0) & 0xFF
    if ord('a') == key:
        i -= 1
    elif ord('d') == key:
        i += 1
